package com.love.netty.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.love.netty.model.UserChatList;
import com.love.netty.model.UserRelation;
import com.love.netty.model.WebUser;
import com.love.netty.model.res.UserChatRes;
import com.love.netty.service.IUserRelationService;
import com.love.netty.service.IWebUserService;
import com.love.netty.service.UserChatListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: UserChatController
 * @Description:
 * @Author: wuj
 * @Date: 2021-07-01 14:49
 **/
@Controller
@RequestMapping("chat")
public class UserChatController {

    @Autowired
    private UserChatListService userChatListService;

    @Autowired
    private IUserRelationService iUserRelationService;


    @Autowired
    private IWebUserService iWebUserService;

    @GetMapping("getChat")
    public String chat(String id, Model model){
        //查询当前登录用户
        WebUser webUser = iWebUserService.getById(id);
        model.addAttribute("webUser",webUser);
        //查询聊天列表
        List<UserChatRes> userChatLists = userChatListService.selectList(id);
        model.addAttribute("userChatLists",userChatLists);
        return "talk/chat";
    }


    @GetMapping("getChatWithOther")
    public String getChatWithOther(String id , Model model, HttpServletRequest request){
        WebUser webUser = (WebUser) request.getSession().getAttribute("loginUser");

        List<UserChatRes> userChatLists = userChatListService.selectList(String.valueOf(webUser.getId()));
        model.addAttribute("userChatLists",userChatLists);

        //查询当前登录用户
        WebUser toUser = iWebUserService.getById(id);
        model.addAttribute("toUser",toUser);


        model.addAttribute("userChatLists",userChatLists);
        model.addAttribute("userId",id);
        model.addAttribute("fromUserId",webUser.getId());
        return "talk/chatWith";
    }



}
